//
//  ForgetPassController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/27.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "ForgetPassController.h"

@interface ForgetPassController ()
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UITextField *codeText;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
- (IBAction)codeBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITextField *passwordText;
@property (weak, nonatomic) IBOutlet UITextField *xinPassText;

@end

@implementation ForgetPassController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"忘记密码";
    self.phoneLabel.text = self.phone;
    
}
- (IBAction)commitBtn:(BoardButton *)sender {
    if ([self.passwordText.text isEqualToString:self.xinPassText.text]) {
        [[ApiManager ShardInstance]forgetPassuserID:self.userid new_pass:self.passwordText.text captcha:self.codeText.text resultBlock:^(NSDictionary *data, NSError *error) {
            BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
            
            if (model.code == 1) {
                NSInteger index=[[self.navigationController viewControllers]indexOfObject:self];
                [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index-2]animated:YES];
                [[ToastManager shardInstance]showToast:@"修改成功"];
            }else{
                
                [[ToastManager shardInstance]showToast:model.msg];
            }
            
            
        }];
        
    }else{
        [[ToastManager shardInstance]showToast:@"密码不一致"];
        
    }
    
}


- (IBAction)codeBtn:(UIButton *)sender {
    
    [[ApiManager ShardInstance]codeuserID:self.userid mobile:self.phoneLabel.text  type:@"0" resultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [AuthCodeManager getValidCode:sender];
            [[ToastManager shardInstance]showToast:model.msg];
        }
        else{
            
             [[ToastManager shardInstance]showToast:model.msg];
        }
        
    }];
}
@end
